<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.util.*"%>
<%@ page import="lib.db.admin.*"%>
<jsp:useBean id="bdAdminDAO" class="lib.db.admin.AdminDAO" scope="session"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK href="../include/default.css" type="text/css" rel="stylesheet">
<SCRIPT src="../include/default.js" type="text/javascript"></SCRIPT>
<title>ADMIN:LIST</title>

</head>

<body>
<%@ include file="../include/header.jsp" %>
<br><br>

<p align="center">
<b><font color="#000080" face="Tahoma" size="4">
DANH SÁCH THÀNH VIÊN QUẢN TRỊ
</font></b>
</p>

<div align="center">

<FORM NAME="frmList" METHOD="POST">
<table border="1" width="60%" bordercolor="#999999" style="border-collapse: collapse" cellspacing="2" cellpadding="2">
  <tr bgcolor="#e0e0e0">
    <td width="5%"  align="center" class="header">&nbsp;</td>
    <td width="20%" align="center" class="header">
	Tên đăng nhập</td>
    <td width="40%" align="center" class="header">
	Tên đầy đủ</td>
    <td width="20%" align="center" class="header">
    	Ngày tạo</td>
    <td width="5%" align="center" class="header">
	Sửa</td>
    <td width="5%" align="center" class="header">
	Quyền</td>
    <td width="5%" align="center" class="header">
    	Xoá</td>
  </tr>

<% //Delete selected rows
    String sAction = request.getParameter("action");
    if(sAction != null && sAction.equals("Delete")) {
        String[] selected = request.getParameterValues("chkID");
        if (selected != null && selected.length > 0) {
            for (int i = 0; i < selected.length; i++) {
                bdAdminDAO.deleteRow(new BigDecimal(selected[i]));
            }
        }
    }
%>

<% // List all rows
    Collection cAdmins = bdAdminDAO.findAll();
    if (cAdmins != null && cAdmins.size() > 0) {
        Admin admin = null;
        String sBGColor = "";
        for (Iterator it = cAdmins.iterator(); it.hasNext(); ) {
            admin = (Admin) it.next();
            if (admin == null) continue;
            if (admin.getStatus() == 1) sBGColor = "#FFFFF8";
            else sBGColor = "#EFEFEF";
%>
  <tr>
    <td width="5%" align="center" valign="middle" bgcolor="<%=sBGColor%>">
        <input type="checkbox" name="chkID" value="<%=admin.getId()%>"></td>
    <td width="20%" align="left" valign="middle" bgcolor="<%=sBGColor%>" class="list">
<%
	if (admin.getStatus() == 1) {
            out.println("<a href=\"lock_resp.jsp?id=" + admin.getId() + "&currStatus=" + admin.getStatus() + "\">");
            out.println("<img src=\"../images/lock1.gif\" width=18 height=18 border=0 alt=\"Lock account\" style=\"cursor:hand;\">");
            out.println("</a>");
	} else {
            out.println("<a href=\"lock_resp.jsp?id=" + admin.getId() + "&currStatus=" + admin.getStatus() + "\">");
            out.println("<img src=\"../images/lock2.gif\" width=18 height=18 border=0 alt=\"UnLock account\" style=\"cursor:hand;\">");
            out.println("</a>");
	}
%>
        <%=admin.getUsername()%></td>
    <td width="40%" align="center" valign="middle" bgcolor="<%=sBGColor%>" class="list">
    	<%=admin.getFullname()%></td>
    <td width="20%" align="center" valign="middle" bgcolor="<%=sBGColor%>" class="list">
             <%=admin.getRegTime()%></td>
    <td width="5%" align="center" valign="middle" bgcolor="<%=sBGColor%>" class="list">
        <a href="edit.jsp?id=<%=admin.getId()%>" style="cursor:hand;">
            <img border="0" src="../images/edit.gif" width="18" height="13" alt="Edit this account">
        </a>
    </td>
    <td width="5%" align="center" valign="middle" bgcolor="<%=sBGColor%>">
        <a href="right_list.jsp?id=<%=admin.getId()%>" style="cursor:hand;">
            <img border="0" src="../images/detail.gif" width="17" height="15" alt="Check rights for this account">
        </a>
    </td>
    <td width="5%" align="center" valign="middle" bgcolor="<%=sBGColor%>">
        <a href="list.jsp?chkID=<%=admin.getId()%>" style="cursor:hand;">
           <img border="0" src="../images/delete.gif" width="15" height="17" alt="Delete this account">
        </a>
    </td>
  </tr>
<%
        } //for()
    } //if(cAdminIds)
%>
  <tr>
    <td width="5%" align="center" bgcolor="#FFFFF8">    </td>
    <td width="95%" align="left"  bgcolor="#FFFFF8" colspan="6">
        <input type="hidden" name="action" value="">
        <input type="button" value="Delete" name="butDelete" class="flatbutton"
            onclick='
                document.frmList.action.value="Delete";
                document.frmList.submit();'>
	<input type="button" value="New..." name="btnNew" class="flatbutton"
            onClick='window.location="add.jsp";'>
    </td>
  </tr>
</table>
</FORM>
</div>

</body>
</html>
